<template>
    <el-dialog :visible.sync="dialog" :title="isAdd ? '教师调配信息' : '编辑教师调配信息'" append-to-body width="450px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px" append-to-body>

            <el-form-item label="是否通过" prop="status" >
                <el-select v-model="form.status" clearable  filterable placeholder="请选择是否通过" style="width: 250px;" >
                    <el-option
                        v-for="item in codestuas"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="拒绝理由" v-if="form.status == 2" prop="dispatchInfo">
                <div style=""></div>
                <el-input v-model="form.dispatchInfo" style="width: 250px;" rows="3" type="textarea" maxlength="100"   show-word-limit clearable/>
            </el-form-item>

        </el-form>

        <div slot="footer" class="dialog-footer">
            <el-button type="text" @click="cancel">取消</el-button>
            <el-button :loading="loading" type="primary" @click="doSubmit" >确认</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { debounce } from '@/utils/validate'
import { dispatchAudit } from '@/api/request'
export default {
    props: {
        isAdd: {
          type: Boolean,
          required: true
        },
        codestuas:{
            type: Array,
            required: true 
        }
    },
    data() {
        return {
            disabled:true,
            loading: false, dialog: false, permissions: [],
            form: {
                id:'',
                status:'',
                dispatchInfo:''
            },
            rules: {
                status:[
                    { required: true, trigger: 'blur',message: '请选择是否通过',},
                ],
                dispatchInfo: [
                    { required: true, trigger: 'blur',message: '请填写拒绝理由',},
                ],
                
            },
        }
    },
    methods: {
        cancel(){
            this.dialog  = false
        },
        doSubmit:debounce(function(){
            // console.log(this.form.id)
            this.$refs['form'].validate((valid) => {
                if (valid){
                    this.form.dispatchInfo = '拒绝理由：'+this.form.dispatchInfo +'。' + '申请理由：'+sessionStorage.getItem("keyDis")
                    dispatchAudit(this.form).then(res => {
                        this.$notify({
                            title: '保存成功',
                            type: 'success',
                            duration: 2500
                        })
                        this.dialog = false
                        this.$parent.init()
                    })
                }else {
                    return false
                }

            })

        },500),

    },



}
</script>


<style scoped lang="scss">
.el-form-item--mini.el-form-item, .el-form-item--small.el-form-item{
    display: inline-block;
}
</style>
